//
//  LBReactMultiPatcher.h
//  LBReactPatcher
//
//  Created by WuShiHai on 19/5/24.
//  Copyright (c) 2019 Lebbay All rights reserved.
//

#import <Foundation/Foundation.h>

#import <LBNetworking/LBAPP.h>
#import <LBReact/LBReact.h>

#import "LBReactPatcherModel.h"

typedef void (^LBReactMultiPatcherUpgradeCompleteBlock)(BOOL isSuccess, NSError *error, BOOL isUpdate);
typedef void (^LBReactMultiPatcherReqeustCompleteBlock)(LBBaseResponse *response, NSError *error);
typedef void (^LBReactMultiPatcherDownloadProgressBlock)(CGFloat progress);

#define LBReactMultiPatcherManager [LBReactMultiPatcher manager]

@interface LBReactMultiPatcher : NSObject

/**
 实例

 @return 实例
 */
+ (instancetype)manager;

/**
设置请求host

@param baseUrl 请求地址
*/
- (void)setBaseUrl:(NSString *)baseUrl;

/**
 启动时候的渲染

 @param launchOptions 启动项
 @param isRender 是否下载完就渲染
 @param isUseDefaultOnly 是否只用本地的
 @param progress 进度回调
 @param complete 完成回调
 */
- (void)renderMainBundle:(NSDictionary *)launchOptions
                isRender:(BOOL)isRender
        isUseDefaultOnly:(BOOL)isUseDefaultOnly
                progress:(LBReactMultiPatcherDownloadProgressBlock)progress
                complete:(LBReactBridgeRenderCompleteBlock)complete;

/// 渲染本地的业务包，前提是主包需要渲染好
/// @param launchOptions 启动项
/// @param bridge 主包bridge
/// @param isRender 是否渲染
/// @param complete 完成回调
- (void)renderLocalAllBusiness:(NSDictionary *)launchOptions
                        bridge:(LBBridge *)bridge
                      isRender:(BOOL)isRender
                      complete:(LBReactBridgeRenderCompleteBlock)complete;

/// 异步检查更新
/// @param complete 更新完成后回调
- (void)upgrade:(LBReactMultiPatcherUpgradeCompleteBlock)complete;

/**
 渲染业务包

 @param level 模块加载级别
 @param bridge 桥接
 @param module 模块名称，多个页面可归为一个模块
 @param complete 完成回调
 */
- (void)renderBusinessBundle:(LBReactBridgeRenderLevel)level
                      bridge:(RCTBridge *)bridge
                      module:(NSString *)module
                    complete:(LBReactBridgeRenderCompleteBlock)complete;

/**
 渲染本地指定的补丁包，如果没有下载会进行下载

 @param patcher 补丁包
 @param bridge bridge
 @param complete 回调
 */
- (void)renderLocalBusinessBundleWith:(LBReactPatcherModel *)patcher
                               bridge:(LBBridge *)bridge
                             complete:(LBReactBridgeRenderCompleteBlock)complete;

/**
 获取当前module本地最新的补丁包

 @param module 模块名称
 @return 补丁对象
 */
- (LBReactPatcherModel *)localLatestPatcherWith:(NSString *)module;

@end
